package com.huanuo.internetofthings.service.user;

import com.huanuo.internetofthings.bo.user.UserInfo;
import com.huanuo.internetofthings.dao.user.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.unicorn.framework.base.base.AbstractService;
import org.unicorn.framework.core.SysCode;
import org.unicorn.framework.core.exception.PendingException;

@Service
public class UserInfoService extends AbstractService {

	@Autowired
	private UserInfoMapper userInfoMapper;
    /**
     * 新增用户信息
     * @param userInfo
     * @return
     * @throws PendingException
     */
	public UserInfo addUserInfo(UserInfo userInfo) throws PendingException {
		try {
			this.userInfoMapper.insert(userInfo);
			return userInfo;
		} catch (Exception e) {
			error("新增用户信息", e);
			throw new PendingException(SysCode.DB_ERROR, "新增用户信息失败");
		}

	}

	/**
	 * 根据主键查询用户信息
	 * 
	 * @param userInfo
	 * @return
	 * @throws PendingException
	 */
	public UserInfo getUserInfo(UserInfo userInfo) throws PendingException {
		try {
			return this.userInfoMapper.selectByPrimaryKey(userInfo.getId());
		} catch (Exception e) {
			error("获取用户信息", e);
			throw new PendingException(SysCode.DB_ERROR, "获取用户信息");
		}
	}

	/**
	 * 根据查询条件获取用户信息
	 * 
	 * @param userInfo
	 * @return
	 * @throws PendingException
	 */
	public UserInfo getUserInfoByCondition(UserInfo userInfo) throws PendingException {
		try {
			return this.userInfoMapper.selectOne(userInfo);
		} catch (Exception e) {
			error("获取用户信息", e);
			throw new PendingException(SysCode.DB_ERROR, "获取用户信息");
		}
	}

}